import judgeType from '@base/utils/judgeType'
const importAll = (context, remove, type) => {
  let temp = null
  if (type === 'array') {
    temp = []
  } else {
    temp = {}
  }
  context.keys().forEach(key => {
    if (remove && judgeRemove(remove, key)) return
    const keyArr = key.split('/')
    var item = keyArr.pop() // 移除.
    item = item.split('.')[0]
    if (type === 'array') {
      temp.push(context(key).default)
      return
    } 
    temp[item] = context(key).default
    
  })
  return temp
}

const judgeRemove  = (removeName, key) => {
  if (judgeType.isString(removeName)) {
    return key.indexOf(removeName) > -1
  }
  if (judgeType.isArray(removeName)) {
    let flag = false
    for(const i of removeName) {
      if (key.indexOf(i) > -1) {
        flag = true
      }
    }
    return flag
  } 
}


export default importAll